﻿// Copyright 2009 William P. Hickey Jr. and William U. Walker
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//     
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//  
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using GMap.NET.ObjectModel;
using GMap.NET.WindowsForms;

namespace CSReporter
{
    class MapOverlay : GMapOverlay
    {
        public Brush TooltipFontBrush = Brushes.Navy;

        internal System.Windows.Forms.GMapControl Control;

        public MapOverlay(System.Windows.Forms.GMapControl control, string id) : base(control, id)
        {
            Control = control;
        }

        /// <summary>
        /// draws tooltip, override to draw custom
        /// </summary>
        /// <param name="g"></param>
        /// <param name="m"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        protected override void DrawToolTip(Graphics g, GMapMarker m, int x, int y)
        {
            GraphicsState s = g.Save();
            g.SmoothingMode = SmoothingMode.AntiAlias;

            System.Drawing.Size st = g.MeasureString(m.ToolTipText, TooltipFont).ToSize();
            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(x, y, st.Width + Control.TooltipTextPadding.Width, st.Height + Control.TooltipTextPadding.Height);
            rect.Offset(m.ToolTipOffset.X, m.ToolTipOffset.Y);

            g.DrawLine(TooltipPen, x, y, rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
            g.FillRectangle(TooltipBackground, rect);
            g.DrawRectangle(TooltipPen, rect);
            g.DrawString(m.ToolTipText, TooltipFont, TooltipFontBrush, rect, TooltipFormat);

            g.Restore(s);
        }
    }
}
